package com.zzyl.service.impl;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 新增
     * @param bedDto 床位信息
     * @return 影响行数
     */
    @Override
    public int addBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto, bed);
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bed.setCreateBy(1L);
        bed.setUpdateBy(1L);
        bed.setBedStatus(0);
        return bedMapper.insert(bed);
    }

    /**
     * 根据id查询床位
     * @param id id
     * @return 床位视图对象
     */
    @Override
    public BedVo getBedById(Long id) {
        Bed bed = bedMapper.selectById(id);
        BedVo bedVo = new BedVo();
        BeanUtils.copyProperties(bed, bedVo);
        return bedVo;
    }

    @Override
    public int updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto, bed);
        bed.setUpdateBy(1L);
        return bedMapper.updateById(bed);
    }
    //删除
    @Override
    public int deleteBedById(Long id) {
        return bedMapper.deleteByPrimaryKey(id);
    }




}

